<template>
  <view class="content">
    <view class="text-xsl" style="margin-top: 30%">
      <text class="cuIcon cuIcon-icloading cuIconfont-spin text-progress"></text>
    </view>
    <view class="margin-top-sm text-brown">登陆中,请稍等...</view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      code: null
    };
  },
  onLoad(ops) {
    // #ifdef H5
    if (ops.code != '' && ops.code != null && ops.code != undefined) {
      this.code = ops.code;
      this.app.getLoginToken(ops.code, ops.qrcode);
    } else {
      uni.navigateTo({
        url: 'login'
      });
    }
    // #endif

    // #ifdef APP
    this.apploginwx();
    // #endif
  },
  methods: {
    apploginwx() {
      var _this = this;
      uni.getProvider({
        service: 'oauth',
        success: function (res) {
          console.log(res.provider);
          //支持微信、qq和微博等
          if (~res.provider.indexOf('weixin')) {
            //用户拥有微信是才会进行一下操作
            uni.login({
              provider: 'weixin',
              success: function (loginRes) {
                console.log('-------获取openid(unionid)-----');
                console.log(JSON.stringify(loginRes));
                var userdata = {};
                // 获取用户信息
                uni.getUserInfo({
                  //进行登录吗，拉起微信弹窗
                  provider: 'weixin',
                  success: function (infoRes) {
                    console.log('-------获取微信用户所有-----');
                    console.log(JSON.stringify(infoRes.userInfo));
                    _this.app.appwxlogin(infoRes.userInfo);
                  }
                });
              },
              fail(e) {
                uni.showToast({
                  title: '微信登录失败，请重新登录',
                  duration: 1000,
                  icon: 'none'
                });
              }
            });
          } else {
            uni.showToast({
              title: '请先安装微信',
              duration: 1000,
              icon: 'none'
            });
          }
        }
      });
    }
  }
};
</script>
<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>
